/*
 * @Author: szx
 * @Date: 2022-03-16 13:57:19
 * @LastEditTime: 2022-03-16 14:02:11
 * @Description:
 * @FilePath: \leetcode\1-99\45\45_2.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var jump = function (nums) {
    let res = 0;
    let max = 0;
    let end = 0;
    for (let i = 0; i < nums.length - 1; i++) {
        max = Math.max(max, i + nums[i]);
        if (i == end) {
            res++;
            end = max;
        }
    }
    return res;
};
console.log(jump([2, 3, 1, 1, 4]));
